package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;

import data.Data;
import data.Lang;
import data.Woche;

public class WeekChooser {
	
	private Data data;
	private JDialog dialog;
	private JComboBox<Woche> dropdownboxWoche;
	
	private int chosenWeekInternalNr = -1;
	
	public WeekChooser(Data data) {
		this.data = data;
		
		dialog = new JDialog();
		dialog.setTitle(Lang.WEEKCHSR_TITLE);
		dialog.setSize(320, 80);
		dialog.setResizable(false);
		dialog.setMinimumSize(dialog.getSize());
		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		dialog.setLocationRelativeTo(null);
		dialog.setLayout(null);
		dialog.setModal(true);
		setupGUI();
		dialog.setVisible(true);
	}
	
	private void setupGUI() {
		dropdownboxWoche = new JComboBox<>();
		dropdownboxWoche.setMaximumRowCount(20);
		dropdownboxWoche.setBounds(10, 10, 180, 25);
		ArrayList<Woche> wochenListe = data.getWochenListe();
		for(int i = 0; i < wochenListe.size(); i++) {
			dropdownboxWoche.addItem(wochenListe.get(i));
		}
		dialog.add(dropdownboxWoche);
		
		JButton btn = new JButton(Lang.WEEKCHSR_BTN_GO);
		btn.setBounds(200, 10, 100, 25);
		btn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				chosenWeekInternalNr = dropdownboxWoche.getSelectedIndex();
				dialog.dispose();
			}
		});
		dialog.add(btn);
	}
	
	public int getChosenWeekInternalNr() {
		return chosenWeekInternalNr;
	}
	
}
